package trabalho.das.fxml.views;

import java.io.File;
import java.io.IOException;
import javafx.embed.swing.SwingFXUtils;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.WritableImage;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.RadialGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.ArcType;
import javax.imageio.ImageIO;
import trabalho.das.fxml.views.controladores.ControladorCriarTelha;

/**
 *
 * @author L
 */
public class CriarTelhaView extends HBox {
    private ControladorCriarTelha controlador;
    private Canvas menuTelhaCanvas;
    
    public CriarTelhaView() {
        controlador = new ControladorCriarTelha();
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/resources/fxml/CriarTelha.fxml"));
        fxmlLoader.setRoot(this);
        fxmlLoader.setController(controlador);

        try {
            fxmlLoader.load();
            menuTelhaCanvas = (Canvas)lookup("#menuTelhaCanvas");
            initCanvas(menuTelhaCanvas.getGraphicsContext2D());
        } catch (IOException exception) {
            throw new RuntimeException(exception);
        }
    }
    
    private void initCanvas(GraphicsContext gc) {
        
        gc.setStroke(Color.BLUE);
        gc.setLineWidth(5);
        gc.strokeLine(40, 10, 10, 40);
        
        menuTelhaCanvas.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent e) -> {
            if(e.isControlDown()) {
                gc.setFill(Color.RED);
                gc.fillRoundRect(e.getX(), e.getY(), 60, 60, 40, 40);
                return;
            }
            if(e.isShiftDown()) {
                gc.setFill(Color.GREEN);
                gc.fillOval(e.getX(), e.getY(), 10, 10);
                return;
            }
            if(e.isAltDown()) {
                gc.setFill(Color.BLUE);
                gc.fillArc(e.getX(), e.getY(), 40, 40, 0, 180, ArcType.OPEN);
                return;
            }
            gc.setFill(Color.BLACK);
            gc.fillRect(e.getX(), e.getY(), 15, 15);
        });
    }
    
    
}
